package online.misscl.lsy.service.impl;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
import online.misscl.lsy.entity.HospitalInformation;
import online.misscl.lsy.entity.VaccineSort;
import online.misscl.lsy.entity.VaccineSortHospital;
import online.misscl.lsy.entity.dto.GetHospitalInformationDTO;
import online.misscl.lsy.entity.dto.vo.HospitalInformationVo;
import online.misscl.lsy.mapper.HospitalInformationMapper;
import online.misscl.lsy.service.HospitalInformationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 医院信息表 服务实现类
 * </p>
 *
 * @author misscl
 * @since 2023/03/11 11:14
 */
@Service
public class HospitalInformationServiceImpl extends ServiceImpl<HospitalInformationMapper, HospitalInformation> implements HospitalInformationService {
    @Override
    public List<HospitalInformationVo> getHospitalBySort(Integer sortId) {
        MPJLambdaWrapper<HospitalInformation> hospitalInformationMPJLambdaWrapper = new MPJLambdaWrapper<>();
        hospitalInformationMPJLambdaWrapper.select(HospitalInformation::getHospitalId,HospitalInformation::getHospitalAddress,
                        HospitalInformation::getHospitalName,HospitalInformation::getHospitalPhone, HospitalInformation::getHospitalImg)
                .leftJoin(VaccineSortHospital.class,VaccineSortHospital::getHospitalId, HospitalInformation::getHospitalId)
                .leftJoin(VaccineSort.class,VaccineSort::getVaccineSortId,VaccineSortHospital::getVaccineSortId)
                .groupBy(HospitalInformation::getHospitalId)
                .eq(sortId != null,VaccineSort::getVaccineSortId,sortId);
//                                            .eq(HospitalInformation::getHospitalId,1);
        return baseMapper.selectJoinList(HospitalInformationVo.class,hospitalInformationMPJLambdaWrapper);
    }

    @Override
    public List<HospitalInformationVo> getHospitalInfo(GetHospitalInformationDTO getHospitalInformationDTO) {
        MPJLambdaWrapper<HospitalInformation> hospitalInformationLambdaQueryWrapper = new MPJLambdaWrapper<>();
        hospitalInformationLambdaQueryWrapper.select(HospitalInformation::getHospitalId,HospitalInformation::getHospitalAddress,
                        HospitalInformation::getHospitalName,HospitalInformation::getHospitalPhone, HospitalInformation::getHospitalImg)
                .like(getHospitalInformationDTO.getHospitalPhone() != null,HospitalInformation::getHospitalPhone,getHospitalInformationDTO.getHospitalPhone())
                .like(getHospitalInformationDTO.getHospitalAddress() != null,HospitalInformation::getHospitalAddress,getHospitalInformationDTO.getHospitalAddress())
                .like(getHospitalInformationDTO.getHospitalName() != null,HospitalInformation::getHospitalName,getHospitalInformationDTO.getHospitalName());
        return baseMapper.selectJoinList(HospitalInformationVo.class,hospitalInformationLambdaQueryWrapper);
    }
}
